package clasificador.redneuronal.neurona;

import java.util.HashSet;
import java.util.Set;
import utils.Logger;


public class GrupoNeuronasSoftmax {

    private Set<Signal<Double>> expSignals;
    public Signal<Double> sumSignal;
    private boolean updated;
    private double sum;
    
    public void invalidate() {
        //Logger.warning("Invalidando");
        sumSignal.invalidate();
    }

    public GrupoNeuronasSoftmax() {
        this.updated = false;
        this.expSignals = new HashSet<>();
        sum = 1.0;
        this.sumSignal = new Signal<Double>() {
            @Override
            public void recalculate() {
                this.value = recalculateSum();
            }
        };
    }

    public void addNeurona(NeuronaSoftmax s) {
        this.expSignals.add(s.expSignal);
    }

    private double recalculateSum() {
        //Logger.info("###RECALCULANDO SUM###");
        double sum = 0.0;

        //Logger.info("Tengo " + expSignals.size() + " elementos.");
        for (Signal<Double> expSignal : expSignals) {
            //Logger.info("Sumando " + expSignal.getValue());
            sum += expSignal.getValue();
            //Logger.info("Van " + sum);
        }

        //Logger.info("Resultado: " + sum);
        //Logger.info("###FIN RECALCULO SUM###");
        return sum;
    }
}
